package training;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_6_27_Training {
    //谁进线下了？II
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[21];
        nums[1] = 25;nums[2] = 21;nums[3] = 18;nums[4] = 16;nums[5] = 15;nums[6] = 14;nums[7] = 13;nums[8]=12;
        nums[9] = 11;nums[10] = 10;nums[11] = 9;nums[12] = 8;nums[13] = 7;nums[14] = 6;nums[15] = 5;nums[16] = 4;
        nums[17] = 3;nums[18] = 2;nums[19] = 1;nums[20] = 0;
        int[][] scorce = new int[31][2];
        for (int i = 0; i <= 30; i++) {
            scorce[i][0] = i;
        }
        scorce[0][1] = 0x3f3f3f3f;
        int[] flag = new int[31];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 20; j++) {
                int x = scanner.nextInt();
                int val = scanner.nextInt();
                scorce[x][1] += nums[val];
                flag[x] = 1;
            }
        }
        Arrays.sort(scorce,(a,b)->{
            return b[1] - a[1];
        });
        for (int i = 1; i <= 30; i++) {
            if(flag[scorce[i][0]]==1) {
                System.out.println(scorce[i][0] + " " + scorce[i][1]);
            }
        }
    }

    //势均力敌
    static List<Integer> list;
    static boolean[] cheak;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        list = new ArrayList<>();
        int n = scanner.nextInt();
        cheak = new boolean[n];
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        dfs(0,n,nums,new StringBuilder());
        int sum = 0;
        for (int i = 0;i<list.size();i++){
            sum += list.get(i);
        }
        sum /= 2;
        int[][] dp = new int[list.size()+1][sum+1];

    }

    public static void dfs(int pos,int n,int[] nums,StringBuilder val){
        if(pos == n){
            int a = Integer.valueOf(val.toString());
            list.add(a*a);
            return;
        }
        for (int i = 0; i < n; i++) {
            if(cheak[i]==false) {
                val.append(nums[i]);
                cheak[i] = true;
                dfs(pos + 1, n, nums, val);
                cheak[i] = false;
                val.deleteCharAt(val.length()-1);
            }
        }
    }
}




